//Friday, November 29 2009
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <sstream>
#include <algorithm>

using namespace std;

class Embassy
{
public:
	int visaApplication(vector <int> forms, int dayLength, int openTime)
	{
		int ret=INT_MAX;
		for(int start=0; start <dayLength; start++) {
			int at=start;
			for(int i=0; i<forms.size(); i++) {
				at+=forms[i];
				int mod=at%dayLength;
				if(mod>openTime) at+=dayLength-mod;
			}
			ret = min(ret, at-start);
		}
		return ret;
	}
};
